#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
from netaddr import IPNetwork,iter_iprange

def myprint(obj, end='\n'):
    sys.stdout.write(str(obj) + end)

def main():
    srctxt='''
2012-5-18; 10.18.56.1; 10.18.57.5; 1024; 585
2012-5-19; 72.55.32.1; 91.33.56.5; 1024; 585
2012-5-20; 128.133.32.1; 128.133.37.5; 1024; 585
2012-5-21; 78.55.32.1; 91.33.56.5; 1024; 585
2012-5-22; 78.55.32.1; 91.33.56.5; 1024; 585
2012-5-23; 78.55.32.1; 91.33.56.5; 1024; 585
2012-5-24; 78.55.32.1; 91.33.56.5; 1024; 585
'''
    range1=('10.18.56.0/255.255.254.0','72.55.32.0/255.255.255.0',)
    range2=(('128.133.32.1','128.133.37.255'),)
    iprange=[]
    for it in range1:
        iprange.extend([str(ip) for ip in IPNetwork(it)])
    for it in range2:
        iprange.extend([str(ip) for ip in list(iter_iprange(it[0],it[1]))])
    #for it in iprange:
    #    myprint(it)
    for line in srctxt.strip().split('\n'):
        t=line.split(';')
        if (t[1].strip() in iprange) and (t[2].strip() in iprange):
            myprint(line)

if __name__ == '__main__':
    main()
    myprint('done')